clear all
set more off

local save_figures_flag=1
local coarse_educ_classification=1

use atus_early, clear

local age_min=25
local age_max=64

keep if age>=`age_min' & age<=`age_max'
keep if student==0


gen educ_ind=.
drop if grade==.

if `coarse_educ_classification'==0 {
	replace educ_ind=1 if grade<=11
	replace educ_ind=2 if grade==12
	replace educ_ind=3 if grade>=13 & grade<=15
	replace educ_ind=4 if grade==16
	replace educ_ind=5 if grade==17
}
if `coarse_educ_classification'==1 {
	replace educ_ind=1 if grade<=12
	replace educ_ind=2 if grade>=13 & grade<=15
	replace educ_ind=3 if grade>=16
}

order dataset educ_ind
sort dataset educ_ind

by dataset educ_ind: egen by_educ_work=wtmean(work), weight(weight)
by dataset: egen all_educ_work=wtmean(work), weight(weight)
by dataset educ_ind: egen by_educ_nonmarketwork=wtmean(nonmarket_work), weight(weight)
by dataset: egen all_educ_nonmarketwork=wtmean(nonmarket_work), weight(weight)
by dataset educ_ind: egen by_educ_childcare=wtmean(child_care_full-child_care_play), weight(weight)
by dataset: egen all_educ_childcare=wtmean(child_care_full-child_care_play), weight(weight)
by dataset educ_ind: egen by_educ_leisure=wtmean(leisure_1+child_care_play), weight(weight)
by dataset: egen all_educ_leisure=wtmean(leisure_1+child_care_play), weight(weight)

quietly by dataset educ_ind: gen dup = cond(_N==1,0,_n)
drop if dup>1


keep dataset educ_ind by_* all_*

rename dataset year

save temp_65_03, replace 




use atus_late.dta, clear 


keep if age>=`age_min' & age<=`age_max'

rename tuyear year


keep if student==0

gen educ_ind=.
drop if grade==.

if `coarse_educ_classification'==0 {
	replace educ_ind=1 if grade<=11
	replace educ_ind=2 if grade==12
	replace educ_ind=3 if grade>=13 & grade<=15
	replace educ_ind=4 if grade==16
	replace educ_ind=5 if grade==17
}
if `coarse_educ_classification'==1 {
	replace educ_ind=1 if grade<=12
	replace educ_ind=2 if grade>=13 & grade<=15
	replace educ_ind=3 if grade>=16
}

order year educ_ind
sort year educ_ind


by year educ_ind: egen by_educ_work=wtmean(work/60*365/52), weight(weight)
by year: egen all_educ_work=wtmean(work/60*365/52), weight(weight)
by year educ_ind: egen by_educ_nonmarketwork=wtmean(nonmarket_work/60*365/52), weight(weight)
by year: egen all_educ_nonmarketwork=wtmean(nonmarket_work/60*365/52), weight(weight)
by year educ_ind: egen by_educ_childcare=wtmean((child_care_full-child_care_play)/60*365/52), weight(weight)
by year: egen all_educ_childcare=wtmean((child_care_full-child_care_play)/60*365/52), weight(weight)
by year educ_ind: egen by_educ_leisure=wtmean((leisure_1+child_care_play)/60*365/52), weight(weight)
by year: egen all_educ_leisure=wtmean((leisure_1+child_care_play)/60*365/52), weight(weight)

quietly by year educ_ind: gen dup = cond(_N==1,0,_n)
drop if dup>1



keep year educ_ind by_* all_*


append using temp_65_03
erase temp_65_03.dta

sort year educ_ind

collapse (mean) by_* all_*, by(year educ_ind) 


gen by_educ_totalwork=by_educ_work+by_educ_nonmarketwork+by_educ_childcare
gen all_educ_totalwork=all_educ_work+all_educ_nonmarketwork+all_educ_childcare

gen by_educ_leisure_broad=16*7-by_educ_totalwork /*8 hours for basic sleep*/
gen all_educ_leisure_broad=16*7-all_educ_totalwork /*8 hours for basic sleep*/


replace by_educ_work=by_educ_work*52
replace by_educ_totalwork=by_educ_totalwork*52
replace by_educ_leisure_broad=by_educ_leisure_broad*52
replace all_educ_work=all_educ_work*52
replace all_educ_totalwork=all_educ_totalwork*52
replace all_educ_leisure_broad=all_educ_leisure_broad*52


sort educ_ind year
by educ_ind: gen norm_by_educ_work=by_educ_work-by_educ_work[3]
by educ_ind: gen norm_by_educ_leisure_broad=by_educ_leisure_broad-by_educ_leisure_broad[3]




twoway (connected norm_by_educ_work year if educ_ind==1, lpattern(solid) msymbol(x) msize(large)  lwidth(0.4)) /*
*/ (connected norm_by_educ_work year if educ_ind==3, lpattern(dash) msymbol(o) msize(large)  lwidth(0.4)), xline(1980, lcolor(black)) /*
*/leg(label (1 "{&le} High School") label(2 "{&ge} College") position(7) ring(0) cols(1)) xlabel(1965[10]2017) ylabel(-200[100]150) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours, change from 1985") ylabel(,grid nogextend) ysize(4)
if `save_figures_flag'==1 {
	graph export "../figures/atus_work_education.png", as(png) replace
	graph export "../figures/atus_work_education.eps", as(eps) replace
}
*black and white
twoway (connected norm_by_educ_work year if educ_ind==1, lpattern(solid) msymbol(x) msize(large)  lwidth(0.4)) /*
*/ (connected norm_by_educ_work year if educ_ind==3, lpattern(dash) msymbol(o) msize(large)  lwidth(0.4)), xline(1980, lcolor(black)) /*
*/leg(label (1 "{&le} High School") label(2 "{&ge} College") position(7) ring(0) cols(1)) xlabel(1965[10]2017) ylabel(-200[100]150) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours, change from 1985") ylabel(,grid nogextend) ysize(4) scheme(s1mono)
if `save_figures_flag'==1 {
	graph export "../figures/atus_work_education_bw.png", as(png) replace
	graph export "../figures/atus_work_education_bw.eps", as(eps) replace
}



twoway (connected norm_by_educ_leisure_broad year if educ_ind==1, lpattern(solid) msymbol(x) msize(large)  lwidth(0.4)) /*
*/ (connected norm_by_educ_leisure_broad year if educ_ind==3, lpattern(dash) msymbol(o) msize(large)  lwidth(0.4)), xline(1980, lcolor(black)) /*
*/leg(label (1 "{&le} High School") label(2 "{&ge} College") position(11) ring(0) cols(1)) xlabel(1965[10]2017) ylabel(-350[100]300) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours, change from 1985") ylabel(,grid nogextend) ysize(4)
if `save_figures_flag'==1 {
	graph export "../figures/atus_leisure_education_leg.png", as(png) replace
	graph export "../figures/atus_leisure_education_leg.eps", as(eps) replace
}
*black and white
twoway (connected norm_by_educ_leisure_broad year if educ_ind==1, lpattern(solid) msymbol(x) msize(large)  lwidth(0.4)) /*
*/ (connected norm_by_educ_leisure_broad year if educ_ind==3, lpattern(dash) msymbol(o) msize(large)  lwidth(0.4)), xline(1980, lcolor(black)) /*
*/leg(label (1 "{&le} High School") label(2 "{&ge} College") position(11) ring(0) cols(1)) xlabel(1965[10]2017) ylabel(-350[100]300) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours, change from 1985") ylabel(,grid nogextend) ysize(4) scheme(s1mono)
if `save_figures_flag'==1 {
	graph export "../figures/atus_leisure_education_leg_bw.png", as(png) replace
	graph export "../figures/atus_leisure_education_leg_bw.eps", as(eps) replace
}



